<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('客户信息列表')" />
</head>
<body class="gray-bg">
	<input id="custId"   name="custId"    type="hidden" />
	<input id="custName" name="custName"  type="hidden" />
	<input id="certNo" name="certNo"  type="hidden" />
	<input id="custType" name="custType"  type="hidden" />
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>客户名称：</label>
                                <input type="text" name="custName"/>
                            </li>
                            <li>
                                <label>证件号码：</label>
                                <input type="text" name="certNo"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="crm:custinfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="crm:custinfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="crm:custinfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('crm:custinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:custinfo:remove')}]];
		var datas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "crm/custinfo";

        $(function() {
            var options = {
                url: prefix + "/query",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "客户信息",
                columns: [{
                    /* checkbox: true */
                    radio: true
                },
                {
                    field: 'custId',
                    title: 'id',
                    visible: true
                },
                {
                    field: 'custName',
                    title: '名称'
                },
                {
                    field: 'custType',
                    title: '客户类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.custType==0) {
                        	return "个人";
                        } else {
                        	return "单位";
                        }
                    }
                },
                {
                    field: 'certNo',
                    title: '社会信用号码/身份号码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.custId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.custId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
		/* 添加用户-选择用户-提交 */
		function submitHandler() {
			var rows = $.table.selectFirstColumns();
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		} else if (rows.length>1) {
       			$.modal.alertWarning("请选择一条记录");
       			return;
       		} else {
       			var rowsData = $('#bootstrap-table').bootstrapTable('getSelections');
       			var row = rowsData[0];
       			$("#custId").val(row.custId);
       			$("#custName").val(row.custName);
       			$("#certNo").val(row.certNo);
       			$("#custType").val(row.custType);
       		}
			
		}
		
		$("#bootstrap-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) {
            var rows = $.common.equals("uncheck-all", e.type) ? rowsBefore : rowsAfter;
   			var row = rows;
   			$("#custId").val(row.custId);
   			$("#custName").val(row.custName);
   			$("#certNo").val(row.certNo);
   			$("#custType").val(row.custType);
            //var rowIds = $.table.affectedRowIds(rows);
            //$("#rowIds").val(rowIds);
        });

    </script>
</body>
</html>